package xyf.p11.other;

/**
 * ClassName: M0108_SetZeros
 * Description:
 * Author: xyf
 * Date: 9/16/22 9:32 PM
 * Version: 1.0
 **/
public class M0108_SetZeros
{
    public void setZeroes(int[][] matrix)
    {
        if (matrix == null)
        {
            return;
        }

        int[] row = new int[matrix.length];
        int[] col = new int[matrix[0].length];

        for (int i = 0; i < matrix.length; i++)
        {
            for (int j = 0; j < matrix[0].length; j++)
            {
                if (matrix[i][j] == 0)
                {
                    row[i] = 1;
                    col[j] = 1;
                }
            }
        }

        for (int i = 0; i < row.length; i++)
        {
            if (row[i] == 1)
            {
                for (int j = 0; j < matrix[0].length; j++)
                {
                    matrix[i][j] = 0;
                }
            }
        }

        for (int j = 0; j < col.length; j++)
        {
            if (col[j] == 1)
            {
                for (int i = 0; i < matrix.length; i++)
                {
                    matrix[i][j] = 0;
                }
            }
        }
    }
}